package com.medical.logback.controller;

import com.medical.logback.response.Result;
import com.medical.logback.response.ResultCode;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther:gzf
 * @Date : 2022/06/23
 */
@RestController
public class ExceptionController implements ErrorController {
    @Override
    public String getErrorPath() {
        return "/error";
    }

    @RequestMapping(value = {"/error"})
    public Result error(HttpServletRequest request, HttpServletResponse response) {
        int status = response.getStatus();
        if (status == 404) {
            return Result.error(ResultCode.ERROR_404);
        }
        return Result.error(ResultCode.ERROR);
    }
}
